import { createRouter, createWebHashHistory } from 'vue-router'
import Layout from '@/views/Layout.vue'

const router = createRouter({
  history: createWebHashHistory(),
  routes: [
    {
      path: '/login',
      name: 'Login',
      component: () => import('@/views/Login.vue'),
      meta: {
        title: '登录'
      }
    },
    {
      path: '/',
      component: Layout,
      redirect: '/dashboard',
      children: [
        {
          path: 'dashboard',
          name: 'Dashboard',
          component: () => import('@/views/Dashboard.vue'),
          meta: {
            title: '首页'
          }
        },
      ]
    },
    {
      path: '/inspect',
      component: Layout,
      meta: {
        title: '系统监测'
      },
      children: [
        {
          path: 'system-check',
          name: 'SystemCheck',
          component: () => import('@/views/inspect/SystemCheck.vue'),
          meta: {
            title: '检查报告'
          }
        },
      ]
    },
  ],
})

router.beforeEach((to, from, next) => {
  to.meta.title && (document.title = to.meta.title)
  next()
})

export default router
